from django.contrib import admin

# Register your models here.
from .models import Market, Food, Price, Page, Err_price


class FoodAdmin(admin.ModelAdmin):
    list_display = ('id','food_name')
    search_fields = ['food_name']
admin.site.register(Food,FoodAdmin)


class MarketAdmin(admin.ModelAdmin):
    list_display = ('id','market_name')

admin.site.register(Market,MarketAdmin)


class PageAdmin(admin.ModelAdmin):

    list_display = ('page_date', 'page_id','page_ok')
    list_filter = ['page_date']

admin.site.register(Page,PageAdmin)


class PriceAdmin(admin.ModelAdmin):

    list_display = ('buy_date', 'page_id', 'food', 'price', 'market')
    list_filter = ['page__page_date']
    search_fields = ['food__food_name']

    def buy_date(self, obj):
        return obj.page.page_date

    def page_id(self, obj):
        return obj.page.page_id

    buy_date.admin_order_field = 'page__page_date'


admin.site.register(Price, PriceAdmin)


class ErrPriceAdmin(admin.ModelAdmin):

    list_display = ('buy_date', 'page_id', 'food', 'price', 'market')
    list_filter = ['page__page_date']
    search_fields = ['food__food_name']

    def buy_date(self, obj):
        return obj.page.page_date

    def page_id(self, obj):
        return obj.page.page_id


    buy_date.admin_order_field = 'page__page_date'


admin.site.register(Err_price, ErrPriceAdmin)